<!DOCTYPE html>
<html>
<head>
    <title>更改挂号--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>
 

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
    $(function () {       
		$('#backid').click(function(){
				window.location.href="index.html";
		 });
    });
    function discriCard(UUserCard)
    {
        UUserCard.substring(6,10)+"-"+UUserCard.substring(10,12)+"-"+UUserCard.substring(12,14);
        //获取性别
        if(parseInt(UUserCard.substr(16,1))%2==1)
        {
            $("#sex1").attr("checked","checked");
            $("#sex2").remove("checked");
            //是男则执行代码 ...
        }
        else
        {
            $("#sex2").attr("checked","checked");
            $("#sex1").remove("checked");
            //是女则执行代码 ...
        }
        //获取年龄
        var myDate = new Date();
        var month = myDate.getMonth() + 1;
        var day = myDate.getDate();
        var age = myDate.getFullYear()-UUserCard.substring(6, 10) - 1;
        if (UUserCard.substring(10,12)<month||UUserCard.substring(10,12)==month&&UUserCard.substring(12,14)<=day)
        {
            age++;
        }
        $("#age").val(age);
        //年龄 age
    }
    window.onload=function()
    {
        var txt=document.getElementById("idCar");
        txt.onblur=function(){discriCard(txt.value);}
    }
    </script>
</head>
<body>
<form action="index.html" method="post" id="myForm" class="definewidth m20">
<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <td width="10%" class="tableleft">姓名</td>
        <td><input type="text" name="hosR_name" value=""/></td>
    </tr>

    <tr>
        <td width="10%" class="tableleft">身份证号</td>
        <td><input type="text" name="hosR_idCar"  id="idCar" value=""/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">社保号</td>
        <td><input type="text" name="hosR_medical" value=""/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">挂号费</td>
        <td><input type="text" name="hosR_regPrice" value=""/>元</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">联系电话</td>
        <td><input type="text" name="hosR_phone" value=""/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">是否自费</td>
        <td><input type="radio" name="hosR_selfPrice" value="0" checked/>否&nbsp;&nbsp;&nbsp;
            <input type="radio" name="hosR_selfPrice" value="1"/>是</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">性别</td>
        <td><input type="radio" name="hosR_sex" id="sex1" value="0" checked/>男&nbsp;&nbsp;&nbsp;
            <input type="radio" name="hosR_sex" id="sex2" value="1"/>女</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">年龄</td>
        <td><input type="text" name="hosR_age" id="age" value=""/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">职业</td>
        <td><input type="text" name="hosR_work" value=""/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">初复诊</td>
        <td><input type="radio" name="hosR_lookDoctor" value="0" checked/>初诊&nbsp;&nbsp;&nbsp;<input type="radio" name="hosR_lookDoctor" value="1"/>复诊</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">所挂科室</td>
        <td><select id="departments" name="hosR_keshi">
            <option>请选择科室</option>
             </select>
        </td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">指定医生</td>
        <td><select id="doctor" name="doctor_id">
            <option>请选择医生</option>
        </select>
        </td>
    </tr>
	<tr>
        <td width="10%" class="tableleft">备注</td>
        <td><textarea name="hosR_remark"></textarea></td>
	</tr>
    <tr>
        <td colspan="2">
			<center>
				<button type="button" id="btn" class="btn btn-primary" type="button">保存</button> &nbsp;&nbsp;<button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
			</center>
		</td>
    </tr>
</table>
</form>
</body>
</html>
<script>
    $(function () {
        loadData2();
     function loadData2(){
            $.ajax({
                type: "GET",//这里必须写POST
                url: "/departments/getlist",
                data: null,
                dataType:"json",
                success: function(vo){
              let list = vo.list;
              let res="";
              for (var i=0;i<list.length;i++){
              res+='<option value="'+list[i].d_id+'">'+list[i].d_name+'</option>';
              }
              $("#departments").append(res);
                }
            });
        }

        $("#departments").change(function () {
                var d_id = $("option:selected").val();
            $.ajax({
                type: "GET",//这里必须写POST
                url: "/departments/"+d_id,
                data: null,
                dataType:"json",
                success: function(vo){
                    let list = vo.obj.doctorList;
                    let res="";
                    $("#doctor").empty().append('<option>'+"请选择医生"+'</option>');

                    for (var i=0;i<list.length;i++){
                        res+='<option value="'+list[i].doctor_id+'">'+list[i].doctor_name+'</option>';
                    }
                    $("#doctor").append(res);
                }
            });
        })
        $("#btn").click(function () {
            var name =$("input[name='hosR_name']").val();
            var idCar = $("input[name='hosR_idCar']").val();
            var ssn = $("input[name='hosR_medical']").val();
            var phone = $("input[name='hosR_phone']").val();
            var work = $("input[name='hosR_work']").val();
            var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
            var reg2=/^[9]\d$/;
            var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;

            if(reg.test(idCar) == false){
                alert("身份证输入不合法");
                return false;
            }
           /* if(reg2.test(ssn) == false){
                alert("社保号输入不合法");
                return false;
            }*/
            if (myreg.test(phone) == false){
                alert("手机号输入不合法");
                return false;
            }
            if(name == ""){
                alert("名字不能为空");
                return false;
            }
            if(work == ""){
                alert("职业不能为空");
                return false;
            }
            $.ajax({
                type: "POST",
                url: "/hosRegister/",
                data: $("#myForm").serialize(),
                dataType:"json",
                success: function(vo){
                    if(vo.code==200) {
                        alert("挂号成功！");
                    }else{
                        alert("添加失败！"+vo.msg);
                    }
                }
            });
        });
    })
</script>